/*
	DIMGA
	Distributed Island Model Genetic Algorithm 

	Copyright (c) 2006 Nikola Sivacki nsivacki@gmail.com

	This program is free software; you can redistribute it and/or
	modify in under the terms of the GNU General Public Licence as
	published by the Free Software Foundation; either version 2 of
	the Licence, or [at your option] any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAT PURPOSE. See the
	GNU General Public Licence for more details.

	You should have received a copy of the GNU General Public Licence
	along with this program; if not, write to the Free Software 
	Foundation Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
// Vivarium.h
#ifndef VIVARIUM_H
#define VIVARIUM_H

#include "genotype.h"
#include "gaevaluator.h"

class Vivarium
{
public:
	Vivarium(long _lSize, long _lGSize, GAEvaluator* _ev, float _fRatio, unsigned char _iAmount);
  Vivarium(const char* file, GAEvaluator* _ev, float _fRatio, unsigned char _iAmount);
	~Vivarium();

  void Randomize();
  void SaveVivarium(const char* file);
	void Evolve(long _lNGens = 1);

	void SetGenome(long _iGenome, unsigned char* _pData);
	void SetMutationRatio(float _mr){ m_fRatio = _mr;}
  float GetMutationRatio() {return m_fRatio;}

  Genotype* GetBest();
    
  long GetPopSize() { return m_lSize;}
	long GetGenSize() { return m_lGSize;}
	unsigned char* GetGenome(long _iGenome) { return m_pop[_iGenome]->GetBytes();}
	
	
private:
	void Selection(long _lElites);
	void Mutation();
	void Combine(Genotype* gSrc, Genotype *gDst);
	void Mutate(Genotype* gSrc, float _fRatio, unsigned char _iAmount);

  void print_genome(Genotype* _g);
  void print_all_genomes();
	
	Genotype** m_pop;
	GAEvaluator* m_ev;
	
	long m_lSize;
  long m_lGSize;
	long m_lElites;
	long m_lBestIndex;
	float m_fRatio;
	unsigned char m_iAmount;
};
#endif //VIVARIUM_H
